<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title>乐鲜生活-我的收藏</title>
	<link rel="shortcut icon" href="favicon.ico" />
	<link rel="bookmark" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="css/myorders.css" />
	<link rel="stylesheet" type="text/css" href="css/base.css" />
	<link rel="stylesheet" type="text/css" href="css/index.css" />
	<link rel="stylesheet" type="text/css" href="css/page.css" />
	<link rel="stylesheet" type="text/css" href="css/collections.css" />
	<link rel="stylesheet" type="text/css" href="css/asyncbox/asyncbox.css" />
	<link rel="stylesheet" type="text/css" href="css/asyncbox/asyncboxoverride.css" />
	<style type="text/css">
		.update {
			padding-top: 12px;
			padding-left: 10px;
			float: left
		}
		
		.changeT {
			float: left
		}
	</style>
</head>
<body>
	<div id="wrapper">
		<div id="header"></div>
		<div class="header distance_top">
			<div class="column_z">
				<ul>
					<li class="fist_li_z">个人中心</li>
					<li class="com_li com_li_color">
						<a href="index.html" class="icon_z_1">首页</a>
					</li>
				</ul>
				<div class="clr"></div>
				<div class="shopping_car">
					<a href="cart.html"> 我的购物车</a> <span class="tips2">0</span>
					<div class="shopping_car_list">
						<p class="first_paragraph"></p>
						<p class="second_paragraph">购物车中还没有商品，赶快选购吧！</p>
					</div>
				</div>
			</div>
		</div>
		<div class="main">
			<ul class="content_z_left">
				<li><a class="com_z">我的订单</a></li>
				<li><a href="unpaidorders.html">待付款订单</a></li>
				<li><a href="paidorders.html">待取货订单</a></li>
				<li><a class="com_z">账户设置</a></li>
				<li><a href="usersetting.html">个人信息</a></li>
				<li><a href="changepassword.html">修改密码</a></li>
				<li><a href="collections.html">我的收藏</a></li>
				<li><a class="com_z">我的钱包</a></li>
				<li><a href="charge.html">充值</a></li>
				<li><a href="transfer.html">转账</a></li>
				<li><a href="bills.html">账单</a></li>
			</ul>
			<div class="content_z_right" id="content_z_right">
				<div id="collections">
				</div>
				<div class="clr"></div>
				<!--图片内容结束 -->
				<div class="header_content_d" id="header_content_d">
					<div class="tcdPageCode"></div>
				</div>
				<div class="clr"></div>
			</div>
			<div class="clr"></div>
			
		</div>
		<div id="footer"></div>
	</div>
	
	<script type="text/javascript" src="js/site/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="js/site/AsyncBox.v1.4.js"></script>
	<script type="text/javascript" src="js/site/validate.js"></script>
	<script type="text/javascript" src="js/site/common.js"></script>
	<script type="text/javascript" src="js/site/constants.js"></script>
	<script type="text/javascript" src="js/site/String.js"></script>
	<script type="text/javascript" src="js/site/jquery.page.js"></script>
	<script type="text/javascript">
		$(function() {
			if (!util.isLogin()) {
				window.location = "login.html";
			}
			findShopCarCount();
			init();
	
		});
	
		// 查找收藏品
		function init() {
			$.postAjax("/collection/findCollection.do", 
				{
					pageSize : 8,
					pageNo : 1
				},
				function(json) {
					if (json.code) {
						asyncbox.tips(json.message, asyncbox.Level.error);
						return;
					}
					var data = json.data || [];
					$(".tcdPageCode").remove();
					$("#header_content_d").append("<div class='tcdPageCode'></div>");
					$("#collections").empty();
					if (data.length) {
						append(data);
						var Pages = Math.ceil(json.total / 8);
						if (Pages == 0) {
							Pages = 1;
						}
						$(".tcdPageCode").createPage({
							pageCount : Pages,
							current : 1,
							backFn : function(p) {
								var data1 = {
									pageSize : 8,
									pageNo : p,
								}
								$.postAjax("/collection/findCollection.do", data1,
									function(json) {
										if (json.code) {
											asyncbox.tips(json.message, asyncbox.Level.error);
											return;
										}
										$("#collections").empty();
										var data = json.data || [];
										if (data.length) {
											append(data);
										}
									}
								);
							}
						});
					} else {
						$("#header_content_d").hide();
						$("#header_content_b").hide();
						$("#content_z_right").append(
							"<p align='center' style='margin-top:30px;font-size:20px;font-weight:bold'><a href='index.html'>您还没有收藏的商品哦~</a></p>");
					}
				}
			);
		}
	
		function append(data) {
			var count = 4;
			for ( var index in data) {
				var pi = data[index].fullPictureUrl;
				var mo = data[index].commodityName;
				var ci = data[index].commodityNo;
				var collId = data[index].id;
				if (index % count == 0 || index == 0) {
					$("#collections").append("<div class='header_content_c' id='?'></div>".format(index));
					var id = "#" + index;
				}
				$(id).append("<div class='one'><a onclick='goodInfo(this)' data='?'><img src='?' width='170px' height='180px' alt=''></img></a><p class='input_p'><a onclick='deleteCollection(this)' data='?_?'>删除</a></p><p style='color:#ff4200;font-size:16px;font-weight:bold'>?元</p><p>?</p><p>?</p></div>"
					.format(ci, pi, data[index].commodityNo, data[index].storeNo, data[index].commodityPrice, mo, data[index].storeName));
			}
		}
	
		//查看购物车数量
		function findShopCarCount() {
			$.postAjax("/commodity/getTrolleyCount.do", {}, function(json) {
				if (json.code) {
					asyncbox.tips(json.message, asyncbox.Level.error);
					return;
				}
				var count = eval("(" + json.data + ")")
				$(".shopping_car>span[class='tips2']").text(count);
			});
		}
	
		// 查看商品的详情
		function goodInfo(obj) {
			var commodityNo = $.trim($(obj).attr("data"));
			window.location = "commodity.html?commodityNo=" + commodityNo;
		}

		function deleteCollection(obj){
			asyncbox.confirm('是否删除该收藏品？', '确认框', function(action) {
				if (action == 'ok') {
					var datas = $(obj).attr("data").split('_');
					$.postAjax("/collection/deleteCollection.do", {
						commodityNo : datas[0],
						storeNo : datas[1]
						}, function(json) {
						if (json.code) {
							asyncbox.tips(json.message, asyncbox.Level.error);
							return;
						}
						asyncbox.tips(json.message, asyncbox.Level.success);
						init();
					});
				}
			});
		}
	</script>
</body>
</html>


